package com.smbms.logistics.listener;

import com.alibaba.fastjson.JSONArray;
import com.smbms.commons.bean.Logistics;
import com.smbms.commons.bean.Orders;
import com.smbms.commons.bean.Orders2;
import com.smbms.commons.service.LogisticsService;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(topic = "ORDER",messageModel = MessageModel.BROADCASTING,consumerGroup ="group_b" )
public class ConsumerListener implements RocketMQListener<String> {
    @Resource
    private LogisticsService logisticsService;
    @Override
    public void onMessage(String s) {
        Orders2 o= JSONArray.parseObject(s, Orders2.class);
        Logistics logistics=new Logistics();
        logistics.setAddress(o.getAddress());
        logistics.setBid(o.getBid());
        logistics.setPhone(o.getPhone());
        logisticsService.saveLogistics(logistics);
    }
}
